package com.lxk.vo.result;

/**
 * @author JohnSoybean
 * @create 2020/3/19 15:54
 * @description 状态码及错误信息工具类
 */
public class CodeMsg {
    private Integer code;
    private String msg;

    private CodeMsg() {
    }
    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    //通用的错误码
    public static CodeMsg SUCCESS = new CodeMsg(0, "success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验错误：%s");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500102, "请求非法");
    public static CodeMsg ACCESS_LIMIT_REACHED= new CodeMsg(500104, "访问太频繁！");
    public static CodeMsg NULL_POINTER= new CodeMsg(500105, "空指针异常");
    public static CodeMsg MYSQL_CRUD_FAIL= new CodeMsg(500106, "Operation failed.");
    public static CodeMsg PARAM_ABSENCE = new CodeMsg(500107, "缺少需要的参数");
    public static CodeMsg INFO_NOT_EXIST = new CodeMsg(500108, "该信息不存在");
    public static CodeMsg NO_HANDLER_FOUND =  new CodeMsg(500109, "404不存在");
    public static CodeMsg REDIS_CONNECT_ERR =  new CodeMsg(500110, "Redis连接失败");

    //登录模块 5002XX
    public static CodeMsg NO_TOKEN = new CodeMsg(500200, "请携带token参数");
    public static CodeMsg INVALID_TOKEN = new CodeMsg(500201, "已过期，请重新登录");
    public static CodeMsg ACCOUNT_BLOCKED = new CodeMsg(500202, "您的账号已被冻结");

    public static CodeMsg WECAHT_CODE_ERR = new CodeMsg(500209, "CODE参数错误！");
    public static CodeMsg GET_ACCESS_TOKEN_ERR = new CodeMsg(500210, "获取access_token出错！");
    public static CodeMsg GET_SESSION_KEY_ERR = new CodeMsg(500211, "获取session_key出错！");
    public static CodeMsg GET_USER_INFO_ERR = new CodeMsg(500212, "获取微信用户信息出错！");
    public static CodeMsg ADD_USER_ERR = new CodeMsg(500213, "添加用户出错！");


    //商品模块 5003XX
    public static CodeMsg GOOD_NOT_EXIST = new CodeMsg(500300, "商品已下架");
    public static CodeMsg PACKAGE_NOT_EXIST = new CodeMsg(500301, "This package has been sold out.");
    public static CodeMsg ADD_CART_FAILED = new CodeMsg(500301, "Add to cart failed.");
    public static CodeMsg ADJUST_CART_FAILED = new CodeMsg(500301, "Failed to change quantity.");
    public static CodeMsg GOOD_NOT_MERCHANT = new CodeMsg(500301, "商品不属于当前配送区域");
    public static CodeMsg EMPTY_GOODS_ADDR = new CodeMsg(500303, "商品地址不能为空");
    public static CodeMsg NO_SUCH_GOODS = new CodeMsg(500304, "没有该商品");
    public static CodeMsg CHANGE_STOCK_FAIL = new CodeMsg(500305, "更改库存及销量失败");
    public static CodeMsg NO_GOODS_STAT = new CodeMsg(500306, "商品状态不存在");
    public static CodeMsg GOOD_STOCK_LACK = new CodeMsg(500307, "Merchandise inventory shortage.");

    //消费券模块 5004XX
    public static CodeMsg TICKET_NOT_EXIST = new CodeMsg(500400, "消费券不存在");
    public static CodeMsg TICKET_USER_ERR = new CodeMsg(500401, "消费券身份校验失败");
    public static CodeMsg TICKET_USED = new CodeMsg(500402, "消费券已使用");
    public static CodeMsg TICKET_EXPIRED = new CodeMsg(500403, "消费券已过期失效");
    public static CodeMsg TICKET_USE_ERR = new CodeMsg(500404, "消费券核销失败");


    //订单及支付模块 5005XX
    public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(500500, "订单不存在");
    public static CodeMsg ORDER_PRICE_ERR = new CodeMsg(500501, "订单价格错误");
    public static CodeMsg WXPAY_READY_ERR = new CodeMsg(500503, "支付宝预付单生成失败");
    public static CodeMsg REPEAT_PAY = new CodeMsg(500504, "订单不可重复支付");
    public static CodeMsg ORDERS_UPD_ERR = new CodeMsg(500505, "订单信息更新失败");
    public static CodeMsg RECHARGE_FAIL = new CodeMsg(500506, "余额充值失败");
    public static CodeMsg RECHARGE_NOT_EXIST = new CodeMsg(500507, "充值套餐不存在");
    public static CodeMsg ORDER_INIT_ERR = new CodeMsg(500508, "订单生成失败");
    public static CodeMsg RECHARGE_INVALID = new CodeMsg(500509, "无效的充值数额");

    //机器操作模块 5006XX
    public static CodeMsg QRCODE_INIT_ERR = new CodeMsg(500600, "二维码生成失败");

    //用户模块 5007XX
    public static CodeMsg USER_NOT_EXIST = new CodeMsg(500700, "用户不存在");
    public static CodeMsg USER_MODIFY_ERR = new CodeMsg(500701, "用户信息修改失败");

    //动态模块 5008XX
    public static CodeMsg DYNAMIC_NOT_EXIST = new CodeMsg(500800, "动态不存在");

    //文件上传模块 5009XX
    public static CodeMsg FILE_TOO_BIG = new CodeMsg(500900, "文件大小超过5M");
    public static CodeMsg FILE_NOT_EXIST = new CodeMsg(500901, "文件不存在");
    public static CodeMsg FILE_UPLOAD_FAIL = new CodeMsg(500902, "文件上传失败");
    public static CodeMsg FILE_TYPE_ERROR = new CodeMsg(500902, "文件类型错误");

    //支付模块 5010XX
    public static CodeMsg ALIPAY_READY_ERR = new CodeMsg(501000, "支付宝预付单生成失败");

    //物业模块 5011XX
    public static CodeMsg ADD_OWNER_ERR = new CodeMsg(501100, "添加业主信息失败");

    //其他模块 5012xx
    public static CodeMsg MESSAGE_SEND_ERR = new CodeMsg(501200, "Message sending failed!");
    public static CodeMsg WRONG_MESSAGE = new CodeMsg(501201, "Empty message!");
    public static CodeMsg CHAT_SEND_ERR = new CodeMsg(501201, "客服消息发送失败");

    //通用错误码 600000
    public static CodeMsg ERR_CODE_MSG = new CodeMsg(600000, "%s");

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public CodeMsg fillArgs(String message) {
        //需要新建对象，否则将模板数据修改了
        CodeMsg codeMsg = new CodeMsg(this.code, this.msg);
        codeMsg.msg = String.format(codeMsg.msg, message);
        return codeMsg;
    }
}
